package com.logos.ruralrevitalization.controller;

import com.logos.ruralrevitalization.entity.OrderCartMapping;
import com.logos.ruralrevitalization.service.OrderCartMappingService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 订单购物车关系表(OrderCartMapping)表控制层
 *
 * @author rose
 * @since 2025-03-29 13:24:36
 */
@RestController
@RequestMapping("/orderCartMapping")
public class OrderCartMappingController {
    /**
     * 服务对象
     */
    @Resource
    private OrderCartMappingService orderCartMappingService;

    /**
     * 分页查询
     *
     * @param orderCartMapping 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<OrderCartMapping>> queryByPage(OrderCartMapping orderCartMapping, PageRequest pageRequest) {
        return ResponseEntity.ok(this.orderCartMappingService.queryByPage(orderCartMapping, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderCartMapping> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.orderCartMappingService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param orderCartMapping 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<OrderCartMapping> add(OrderCartMapping orderCartMapping) {
        return ResponseEntity.ok(this.orderCartMappingService.insert(orderCartMapping));
    }

    /**
     * 编辑数据
     *
     * @param orderCartMapping 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<OrderCartMapping> edit(OrderCartMapping orderCartMapping) {
        return ResponseEntity.ok(this.orderCartMappingService.update(orderCartMapping));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.orderCartMappingService.deleteById(id));
    }

}

